package com.project.controller;

import com.project.bean.CommentBean;
import com.project.bean.UserBean;
import com.project.service.ICommentService;
import com.project.service.INewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("comment")
public class CommentController {
    @Autowired
    private ICommentService commentService;
    /**显示新闻评论*/
    @GetMapping("findById")
    public List<CommentBean> findById(Integer newId){
        return commentService.findById(newId);
    }
    /**发表评论*/
    @PostMapping("add")
    public String add(CommentBean commentBean, HttpServletRequest request){
        UserBean user = (UserBean) request.getSession().getAttribute("loginUser");
        commentBean.setUser(user.getUserName());
        commentService.add(commentBean);
        return "评论成功";
    }
}
